import android.content.Context
import android.content.res.Configuration
import androidx.compose.material3.ButtonColors
import androidx.compose.material3.CardColors
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.IconButtonColors
import androidx.compose.material3.MenuItemColors
import androidx.compose.material3.TextFieldColors
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color

class AppColor {
    companion object{
        private val DARK_BACKGROUND_COLOR_1 = Color(0xFF1E2738)
        private val DARK_BACKGROUND_COLOR_2 = Color(0xFF2B3650)

        fun isSystemInDarkTheme(context: Context): Boolean {
            val nightModeFlags = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
            return nightModeFlags == Configuration.UI_MODE_NIGHT_YES
        }

        fun Background(context: Context): Color{
            return if(!isSystemInDarkTheme(context))
                Color.White
            else
                DARK_BACKGROUND_COLOR_1
        }

        fun SystemNavigationBar(context: Context): Color{
            return if(!isSystemInDarkTheme(context))
                Color(0xFFF5F5F5)
            else
                Color(0xFF303136)
        }

        fun IconButton(context: Context): IconButtonColors{
            return if(!isSystemInDarkTheme(context))
                IconButtonColors(
                    contentColor = Color.Black,
                    containerColor = Color.Transparent,
                    disabledContentColor = Color.Black,
                    disabledContainerColor = Color.Transparent
                )
            else
                IconButtonColors(
                    contentColor = Color.LightGray,
                    containerColor = Color.Transparent,
                    disabledContentColor = Color.LightGray,
                    disabledContainerColor = Color.Transparent
                )
        }

        @Composable
        fun TextFieldDefaults(context: Context): TextFieldColors{
            return if(!isSystemInDarkTheme(context))
                TextFieldDefaults.colors(
                    focusedIndicatorColor = Color.Transparent,
                    unfocusedIndicatorColor = Color.Transparent,
                    focusedContainerColor = Color.Transparent,
                    unfocusedContainerColor = Color.Transparent,
                    focusedTextColor = Color.Black,
                    unfocusedTextColor = Color.DarkGray
                )
            else
                TextFieldDefaults.colors(
                    focusedIndicatorColor = Color.Transparent,
                    unfocusedIndicatorColor = Color.Transparent,
                    focusedContainerColor = Color.Transparent,
                    unfocusedContainerColor = Color.Transparent,
                    focusedTextColor = Color.LightGray,
                    unfocusedTextColor = Color.LightGray
                )
        }

        fun SettingCard(context: Context): CardColors{
            return if(!isSystemInDarkTheme(context))
                CardColors(
                    containerColor = Color.White,
                    contentColor = Color.Black,
                    disabledContentColor = Color.White,
                    disabledContainerColor = Color.Black
                )
            else
                CardColors(
                    containerColor = DARK_BACKGROUND_COLOR_1,
                    contentColor = Color.LightGray,
                    disabledContentColor = DARK_BACKGROUND_COLOR_1,
                    disabledContainerColor = Color.LightGray
                )
        }

        fun BookListCard(context: Context): CardColors{
            return if(!isSystemInDarkTheme(context))
                CardColors(
                    contentColor = Color.Black,
                    containerColor = Color.White,
                    disabledContentColor = Color.Black,
                    disabledContainerColor = Color.White
                )
            else
                CardColors(
                    contentColor = Color.LightGray,
                    containerColor = DARK_BACKGROUND_COLOR_2,
                    disabledContentColor = Color.LightGray,
                    disabledContainerColor = DARK_BACKGROUND_COLOR_2
                )
        }

        fun CoverBackground(context: Context): Color{
            return Color(0xFFFBFBFB)
        }

        fun MaybeLookingForButton(context: Context): ButtonColors{
            return if(!isSystemInDarkTheme(context))
                ButtonColors(
                    contentColor = Color.Black,
                    containerColor = Color(0xFFE5E5E5),
                    disabledContentColor = Color.Black,
                    disabledContainerColor = Color(0xFFE5E5E5)
                )
            else
                ButtonColors(
                    contentColor = Color.LightGray,
                    containerColor = DARK_BACKGROUND_COLOR_2,
                    disabledContentColor = Color.LightGray,
                    disabledContainerColor = DARK_BACKGROUND_COLOR_2
                )
        }

        fun DeleteButton(context: Context): ButtonColors{
            return if(!isSystemInDarkTheme(context))
                ButtonColors(
                    contentColor = Color.LightGray,
                    containerColor = Color(0xFFFD5869),
                    disabledContentColor = Color.LightGray,
                    disabledContainerColor = Color(0xFFFD5869)
                )
            else
                ButtonColors(
                    contentColor = Color(0xFF1E1F22),
                    containerColor = Color(0xFFFD5869),
                    disabledContentColor = Color(0xFF1E1F22),
                    disabledContainerColor = Color(0xFFFD5869)
                )
        }

        fun ConfirmButton(context: Context): ButtonColors{
            return if(!isSystemInDarkTheme(context))
                ButtonColors(
                    contentColor = Color.DarkGray,
                    containerColor = Color(0xFF4C93FC),
                    disabledContentColor = Color.DarkGray,
                    disabledContainerColor = Color(0xFF4C93FC)
                )
            else
                ButtonColors(
                    contentColor = Color(0xFF3F3F3F),
                    containerColor = Color(0xFF4C93FC),
                    disabledContentColor = Color(0xFF3F3F3F),
                    disabledContainerColor = Color(0xFF4C93FC)
                )
        }

        fun DropdownButton(context: Context): ButtonColors{
            return if(!isSystemInDarkTheme(context))
                ButtonColors(
                    contentColor = Color.Black,
                    containerColor = Color.Transparent,
                    disabledContentColor = Color.Transparent,
                    disabledContainerColor = Color.LightGray
                )
            else
                ButtonColors(
                    contentColor = Color.LightGray,
                    containerColor = Color.Transparent,
                    disabledContentColor = Color.Transparent,
                    disabledContainerColor = Color.LightGray
                )
        }

        fun DropDownMenuBackground(context: Context): Color{
            return if(!isSystemInDarkTheme(context))
                Color.White
            else
                DARK_BACKGROUND_COLOR_2
        }

        fun DropdownItem(context: Context): MenuItemColors {
            return if(!isSystemInDarkTheme(context))
                MenuItemColors(
                    textColor = Color.Black,
                    leadingIconColor = Color.Black,
                    trailingIconColor = Color.Black,
                    disabledTextColor = Color.Black,
                    disabledLeadingIconColor = Color.Black,
                    disabledTrailingIconColor = Color.Black
                )
            else
                MenuItemColors(
                    textColor = Color.LightGray,
                    leadingIconColor = Color.LightGray,
                    trailingIconColor = Color.LightGray,
                    disabledTextColor = Color.LightGray,
                    disabledLeadingIconColor = Color.LightGray,
                    disabledTrailingIconColor = Color.LightGray
                )
        }
    }

}

